package com.yanqu.road.server.pb;

import com.yanqu.road.entity.player.UserBeauty;
import com.yanqu.road.entity.player.UserInfo;
import com.yanqu.road.entity.wineshop.*;
import com.yanqu.road.pb.beauty.BeautyProto;
import com.yanqu.road.pb.wineshop.WineShopProto;

import java.util.List;
import java.util.Map;

/**
 * @author ：zfr
 * @date ：2021/7/20 10:13
 */
public class WineShopPb {
    public static WineShopProto.WineShopDataSync.Builder parseWineShopData(UserWineShopData data, Map<Integer, UserWineShopBuilding> buildingMap) {
        WineShopProto.WineShopDataSync.Builder builder = WineShopProto.WineShopDataSync.newBuilder();
        builder.setUnlockRegion(data.getUnlockRegion());
        builder.setPower(data.getPower());
        builder.setLastRecoverPowerTime(data.getLastRecoverPowerTime());
        builder.setWaitGenerateCount((int) data.getWaitGenerateCount());
        for (WineShopBeautyArray waitWineShopBeautyArray : data.getWaitWineShopBeautyArrays()) {
            builder.addWaitArray(parseArray(waitWineShopBeautyArray));
        }
        for (WineShopBeautyArray runningBeautyArray : data.getRunningBeautyArrays()) {
            builder.addRunningArray(parseArray(runningBeautyArray));
        }
        builder.setPopularityValue(data.getPopularityValue());
        builder.setReceptionBeautyCount(data.getReceptionBeautyCount());
        builder.setLastReceptionBeautyTime(data.getLastReceptionBeautyTime());
        builder.setWineShopName(data.getWineShopName());
        builder.setWineShopLv(data.getWineShopLv());
        builder.setYieldReward(parseReward(data.getYieldReward()));
        builder.setGetRewardTime(data.getGetRewardTime());
        for (UserWineShopBuilding building : buildingMap.values()) {
            builder.addBuilding(parseBuildingTemp(building));
        }
        builder.setChangeNameTimes(data.getChangeNickNameTimes());
        return builder;
    }

    public static WineShopProto.WineShopBeautyArrayTemp.Builder parseArray(WineShopBeautyArray array) {
        WineShopProto.WineShopBeautyArrayTemp.Builder temp = WineShopProto.WineShopBeautyArrayTemp.newBuilder();
        temp.setArrayId(array.getArrayId());
        temp.setGenerateTime(array.getGenerateTime());
        temp.setEnterWineShopTime(array.getEnterWineShopTime());
        for (WineShopBeauty wineShopBeauty : array.getWineShopBeautyList()) {
            temp.addBeauty(parseBeauty(wineShopBeauty));
        }
        return temp;
    }

    public static WineShopProto.WineShopBeautyTemp.Builder parseBeauty(WineShopBeauty beauty) {
        WineShopProto.WineShopBeautyTemp.Builder temp = WineShopProto.WineShopBeautyTemp.newBuilder();
        temp.setId(beauty.getId());
        temp.setBeautyId(beauty.getBeautyId());
        temp.setEnterWineShopTime(beauty.getEnterWineShopTime());
        temp.setIsExit(beauty.isExit());
        temp.addAllRegion(beauty.getRegionList());
        return temp;
    }

    public static WineShopProto.WineShopRewardTemp.Builder parseReward(WineShopReward reward) {
        WineShopProto.WineShopRewardTemp.Builder temp = WineShopProto.WineShopRewardTemp.newBuilder();
        for (WineShopBeautyReward beautyReward : reward.getBeautyRewardMap().values()) {
            temp.addBeautyReward(parseBeautyTemp(beautyReward));
        }
        temp.setBeautyCount(reward.getBeautyCount());
        temp.setPatronsCount(reward.getPatronsCount());
        return temp;
    }

    public static WineShopProto.WineShopBeautyRewardTemp.Builder parseBeautyTemp(WineShopBeautyReward beautyReward) {
        WineShopProto.WineShopBeautyRewardTemp.Builder temp = WineShopProto.WineShopBeautyRewardTemp.newBuilder();
        temp.setBeautyId(beautyReward.getBeautyId());
        temp.setMoney(beautyReward.getMoneyValue());
        temp.setExp(beautyReward.getExpValue());
        return temp;
    }

    public static WineShopProto.WineShopBuildingTemp.Builder parseBuildingTemp(UserWineShopBuilding building) {
        WineShopProto.WineShopBuildingTemp.Builder temp = WineShopProto.WineShopBuildingTemp.newBuilder();
        temp.setBuildingId(building.getId());
        temp.setLv(building.getLv());
        return temp;
    }

    public static WineShopProto.VisitOtherWineShopRespMsg.Builder parseVisitWineShopMsg(UserWineShopData data, Map<Integer, UserWineShopBuilding> buildingMap, UserInfo userInfo, List<UserBeauty> beautyList) {
        WineShopProto.VisitOtherWineShopRespMsg.Builder respMsg = WineShopProto.VisitOtherWineShopRespMsg.newBuilder();
        respMsg.setUserData(PlayerPb.parsePlayerBaseTempMsg(userInfo));
        respMsg.setUnlockRegion(data.getUnlockRegion());
        for (UserWineShopBuilding userWineShopBuilding : buildingMap.values()) {
            respMsg.addBuilding(parseBuildingTemp(userWineShopBuilding));
        }
        respMsg.setNickName(data.getWineShopName());
        respMsg.setPopularityValue(data.getPopularityValue());
        BeautyProto.BeautyListMsg.Builder listMsg = BeautyPb.parseBeautyListMsg(beautyList);
        respMsg.setBeautyList(listMsg);
        return respMsg;
    }
}
